package com.ttg.web.juc;


import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MoreExecutorServiceUtils {
    static ListeningExecutorService executorService;
    private static Integer coreSize=Runtime.getRuntime().availableProcessors()*2;//主要做网络通讯 属于Io密集型 适当调大


    private static Integer allowSize=coreSize*4;//协助最大等待任务数量 超过数量则由主线程自己做
    public  static ListeningExecutorService   init(){
        executorService=MoreExecutors.listeningDecorator( new ThreadPoolExecutor(

                coreSize, coreSize, 0, TimeUnit.DAYS,
                new ArrayBlockingQueue<Runnable>(coreSize),
                new CallerRunsPolicyForDiy()));
        return  executorService;
    }

}

 